//
//  LGServiceExpiresController.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/8/12.
//  服务包到期

#import "LGServiceExpiresController.h"
#import "LGPatientDetailController_YHJK.h"
#import "LGPatientDetailController2.h"
#import "LGPatientSignHistoryController.h"
#import "LGServiceExpiresCell.h"
@interface LGServiceExpiresController ()<UITableViewDelegate,UITableViewDataSource,LGServiceExpiresDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation LGServiceExpiresController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"近14天服务包到期";
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.view frame:self.tableView.frame];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/vip/dueVipList" parameters:@{} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (code == 200) {
            self.dataArray = returnData;
            self.title = [NSString stringWithFormat:@"近14天服务包到期(%ld)",self.dataArray.count];
        }
        [self.tableView reloadData];
        if (self.dataArray.count == 0) {
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (self.dataArray.count == 0) {
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
        }
    }];
}

//患者档案
-(void)checkPatientDetail:(NSDictionary *)dataDic{
    //癌症-患者详情
    NSString *nodePage = LGNSString(dataDic[@"nodepage"]);
    if ([nodePage isEqualToString:@"1"]) {
        //市一慢阻肺
        LGPatientDetailController2 *controller = [[LGPatientDetailController2 alloc]init];
        controller.patientid = LGNSString(dataDic[@"patient_id"]);
        controller.levelid = LGNSString(dataDic[@"level_id"]);
        controller.diseaseCode = LGNSString(dataDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }else{
        //其他
        LGPatientDetailController_YHJK *controller = [[LGPatientDetailController_YHJK alloc]init];
        controller.patientid = LGNSString(dataDic[@"patient_id"]);
        controller.levelid = LGNSString(dataDic[@"level_id"]);
        controller.diseaseCode = LGNSString(dataDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGServiceExpiresCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.type = LGPositionTypeSingle;
    cell.dataDic = self.dataArray[indexPath.row];
    cell.delegate = self;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    LGPatientSignHistoryController *controller = [[LGPatientSignHistoryController alloc]init];
    controller.patientid = LGNSString(tempDic[@"patient_id"]);
    controller.levelid = LGNSString(tempDic[@"level_id"]);
    [self.navigationController pushViewController:controller animated:YES];
}


-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight) style:UITableViewStylePlain];
        [_tableView registerClass:[LGServiceExpiresCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}

@end
